package com.szcinda.fitness.controller;

import com.szcinda.fitness.CoachService;
import com.szcinda.fitness.controller.utils.Result;
import com.szcinda.fitness.dto.CoachDto;
import com.szcinda.fitness.dto.CoachRegistrationDto;
import com.szcinda.fitness.dto.RelationshipDto;
import com.szcinda.fitness.persistence.Relationship;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/coach")
public class CoachController {

    private final CoachService coachService;

    public CoachController(CoachService coachService) {
        this.coachService = coachService;
    }

    @GetMapping("check/{openId}")
    public Result check(@PathVariable String openId) {
        if (coachService.checkIsExist(openId)) {
            return Result.success();
        } else {
            return Result.fail("此教练OPENID没有注册");
        }
    }

    @GetMapping("/{openId}")
    public Result<CoachDto> getCoach(@PathVariable String openId) {
        return Result.success(coachService.getCoach(openId));
    }


    @PostMapping("registration")
    public Result registration(@RequestBody CoachRegistrationDto registrationDto) {
        coachService.registration(registrationDto);
        return Result.success();
    }

    @PostMapping("addTrainee")
    public Result addTrainee(@RequestBody Relationship relationship) {
        coachService.addTrainee(relationship);
        return Result.success();
    }

    @GetMapping("coachList")
    public Result<List<CoachDto>> query() {
        return Result.success(coachService.query());
    }

    @GetMapping("traineeList/{openId}")
    public Result<List<RelationshipDto>> traineeList(@PathVariable String openId) {
        return Result.success(coachService.traineeList(openId));
    }
}
